package com.ityedao.接口案例;

import java.util.ArrayList;

public class StudentOperatorImpl2 implements StudentOperator{
    @Override
    public void printAllInfo(ArrayList<Student> students) {
        System.out.println("-----------全班信息如下------------");
        int countBoys = 0;
        int countGirls = 0;
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            if (s.getSex().equals("男")){
                countBoys ++;
            }else {
                countGirls ++;
            }
            System.out.println("姓名：" + s.getName() + "性别：" + s.getSex() + "分数：" + s.getScore());
        }
        System.out.println("男生人数共有：" + countBoys + "女生人数：" + countGirls);
        System.out.println("班级总人数是：" + students.size());
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {
        System.out.println("--------全班平均成绩如下----------");
        double allScores = 0.0;
        double maxScore = students.get(0).getScore();
        double minScore = students.get(0).getScore();
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            if (s.getScore() > maxScore)  maxScore = s.getScore();
            if (s.getScore() < minScore)  minScore = s.getScore();
            allScores += s.getScore();
        }
        System.out.println("全班最高分是：" + maxScore);
        System.out.println("全班最低分是：" + minScore);
        System.out.println("全班平均成绩：" + (allScores - minScore - maxScore) / (students.size() - 2));
    }
}
